@extends('admin.public.master')
@section('content')
    <div class="content-wrapper">
        <div class="content-wrapper-before"></div>
        <div class="content-header row">
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('classify.classify.index')}}"><h5 class="content-header-title">分类列表</h5></a>
            </div>
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('classify.classify.create')}}"><h5 class="content-header-title">添加分类</h5></a>
            </div>
        </div>
        <div class="content-body">
            <div class="card">
                <div class="card-body table-responsive">
                    <table class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>分类编号</th>
                            <th>分类名</th>
                            <th>父级分类</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($classifys as$k=> $classify)
                        <tr>
                            <td class="mr-auto mt-auto" scope="row">{{$classify->id}}</td>
                            <td class="mr-auto mt-auto">{{$classify->name}}</td>
                            <td class="mr-auto mt-auto">{{$classify->classifyFather?$classify->classifyFather->name:'顶级分类'}}</td>
                            <td class="mr-auto mt-auto">
                                <a href="{{route('classify.classify.edit',$classify)}}"><button type="button" class="btn btn-info ">编辑</button></a>
                                <button onclick="del(this)" type="button" class="btn btn-danger">删除</button>
                                <form action="{{route('classify.classify.destroy',$classify)}}" method="post">
                                    @csrf @method('DELETE')
                                </form>
                            </td>
                        </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
            <div class="card-footer text-muted">
               {{$classifys->links()}}
            </div>

    </div>
@endsection
@push('js')
    <script>
        function del(obj) {
            swal({
                title: '确定删除吗？',
                text: '你将无法恢复它！',
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '确定删除！',
                cancelButtonText: '取消删除！',
                confirmButtonClass: 'btn btn-success',
                cancelButtonClass: 'btn btn-danger',
                buttonsStyling: false
            }).then(function(value) {
              if(value.value){
                  $(obj).next('form').submit();
              }
            })

        }
    </script>
    @endpush
